package com.tree.service.impl;

import com.tree.dao.ArticleDao;
import com.tree.entity.Article;
import com.tree.service.ArticleService;
import com.tree.util.PageCal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    private ArticleDao articleDao;
    @Override
    public List<Article> queryAll(int pageIndex, int rowSize) {
        //将页数转换为行数
        int rowIndex = PageCal.calculateRowIndex(pageIndex,rowSize);
        List<Article> list = new ArrayList<>();
        list = articleDao.queryAll(rowIndex,rowSize);
        return list;
    }

    @Override
    public Article query(String flowerName) {

        Article article;
        article = articleDao.query(flowerName);
        if (article != null && article.getAcName() != null)
            return article;
        return null;
    }

    @Override
    public List<Article> querySearch(String acName) {
        return articleDao.querySearch(acName);
    }
}
